package com.baidu.service.impl;

import com.baidu.model.entity.MarkModel;
import com.baidu.response.ResponseBody;
import com.baidu.service.InMarkControllerService;
import com.until.pagination.PaginationRequest;
import com.until.response.RestfulCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author user
 */
@Service
public class MarkControllerServiceImpl implements InMarkControllerService {

    @Autowired
    private RestfulCode restfulCode;

    @Autowired
    private ResponseBody responseBody;

    @Autowired
    private MarkServiceImpl markService;

    @Override
    public RestfulCode.CodeSatCode createMark(MarkModel markModel) {
        RestfulCode.CodeSatCode userActionFailed = null;
        try {
            int successfully=markService.createMark(markModel);
            userActionFailed=successfully>0?responseBody.USER_OPERATION_SUCCEEDED:responseBody.USER_ACTION_FAILED;
        } catch (Exception e) {
            userActionFailed=responseBody.USER_INFO_EXCEPTION;
        }
        return restfulCode.getFreeResult(userActionFailed);
    }

    @Override
    public RestfulCode.CodeSatCode selectMarkByPhotoId(PaginationRequest paginationRequest, Integer id) {
        RestfulCode.CodeSatCode userActionFailed=responseBody.USER_OPERATION_SUCCEEDED;
        userActionFailed.setData(markService.selectMarkByPhotoId(paginationRequest,id));
        return userActionFailed;
    }

    @Override
    public RestfulCode.CodeSatCode updateMarkById(MarkModel markModel) {
        RestfulCode.CodeSatCode userActionFailed = null;
        try {
            int successfully = markService.updateMarkById(markModel);
            userActionFailed=successfully>0?responseBody.USER_OPERATION_SUCCEEDED:responseBody.INTERNAL_SERVER_ERROR;
        }catch (Exception e){
            userActionFailed=responseBody.INTERNAL_SERVER_ERROR;
        }
        return userActionFailed;
    }

    @Override
    public RestfulCode.CodeSatCode deleteMarkById(Integer id) {
        RestfulCode.CodeSatCode userActionFailed = null;
        try {
            int successfully = markService.deleteMarkById(id);
            userActionFailed=successfully>0?responseBody.USER_OPERATION_SUCCEEDED:responseBody.NOT_FOUND_EXAMPLE;
        }catch (Exception e){
            userActionFailed=responseBody.INTERNAL_SERVER_ERROR;
        }
        return userActionFailed;
    }
}
